package com.sky.controller.admin;

import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.pojo.Courier;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.user.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;
    @ApiOperation("查询订单")
    @GetMapping("/conditionSearch")
    public Result<PageResult> OrderQuery(OrdersPageQueryDTO queryDTO){
       PageResult pageResult = orderService.OrderQuery(queryDTO);
       return Result.success(pageResult);
    }
    @GetMapping("statistics")
    public Result<OrderStatisticsVO> statistics(){
      OrderStatisticsVO vo =  orderService.statistics();
        return Result.success(vo);
    }
    @ApiOperation("详情订单查询")
    @GetMapping("/details/{orderId}")
    public Result<OrderVO> selectOrder(@PathVariable Long orderId){
        OrderVO orderVO =  orderService.selectById(orderId);
        return Result.success(orderVO);
    }
    @ApiOperation("拒单功能")
    @PutMapping("/rejection")
    public Result<String> rejection(@RequestBody OrdersRejectionDTO dto) throws IOException {
        log.info("拒单功能接收参数:{}",dto);
        orderService.rejection(dto);
        return Result.success();
    }
    @ApiOperation("商家接单")
    @PutMapping("/confirm")
    public Result<Courier> confirm(@RequestBody OrdersConfirmDTO dto) throws InterruptedException {
        Courier courier = orderService.confirm(dto);
        return Result.success(courier);
    }
}
